package app.android.alampang.ui.adapter;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.Collection;

import app.android.alampang.R;
import app.android.alampang.loader.FontLoader;
import app.android.alampang.model.Place;
import app.android.alampang.ui.core.BaseListAdapter;

/**
 * Created by Supanut on 1/18/2015.
 */

public class PlaceListAdapter extends BaseListAdapter<Place> {
    private ArrayList<Place> items = new ArrayList<Place>();

    public PlaceListAdapter(Context context) {
        super(context);
    }

    @Override
    public Place get(int position) {
        return items.get(position);
    }

    @Override
    public void remove(int position) {
    }

    @Override
    public void set(int position, Place item) {

    }

    @Override
    public void add(Place item) {
        items.add(item);
    }

    @Override
    public void setItems(Collection<Place> items) {
        this.items = new ArrayList<>(items);
    }

    @Override
    public int getCount() {
        return items.size();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View view = null;
        if (view == null)
        {
            LayoutInflater inflater = (LayoutInflater) getContext()
                    .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
            view = inflater.inflate(R.layout.custom_listview_menu_place, parent, false);

            Place place = items.get(position);
            ImageView imageView = (ImageView) view.findViewById(R.id.img_place);
            imageView.setImageResource(place.getImageDrawable());

            TextView tv = (TextView) view.findViewById(R.id.txt_placeName);
            tv.setText(place.getName());
            tv.setTypeface(FontLoader.getFont(getContext(), 1));

            View hilight = view.findViewById(R.id.view_hilight);
            hilight.setBackgroundColor(Color.parseColor(place.getHilightColor()));
        }
        else
        {
            view = convertView;
        }




        return view;
    }
}
